<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>05.form_fields | KnockOut</title>
  <script src="../assets/knockout-3.5.1.js"></script>
</head>
<body>

  <p>爱好: <input type="checkbox" data-bind="checked: hobby" /></p>
  <div data-bind="visible: hobby">
    请选择您的爱好:
    <div><input type="checkbox" value="music" data-bind="checked: hobbies" /> 音乐</div>
    <div><input type="checkbox" value="shopping" data-bind="checked: hobbies" /> 购物</div>
    <div><input type="checkbox" value="fishing" data-bind="checked: hobbies" /> 钓鱼</div>
  </div>
    
  <script type="text/javascript">
    var vm = {
      hobby: ko.observable(true),
      hobbies: ko.observableArray(["music","shopping"]) // 初始化数组
    };
    ko.applyBindings(vm);
    
    // ... then later ...
    vm.hobby(false);
    vm.hobbies.push("fishing"); // 向数组中添加元素
  </script>

</body>
</html>
